library CameraEffectSystem requires GlobalVariables

	function FPSCheck takes nothing returns boolean
		local integer i=1
		loop
			exitwhen i>udg_InitialPlayers
			if udg_FPSMode[udg_Sorted[i]]==true then
				return false
			endif
			set i=i+1
		endloop
		return true
	endfunction

	function WhiteFlash takes nothing returns nothing
		local integer i = 1
		call CinematicFilterGenericBJ( 0.35, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0.0, 100, 0.0, 100, 100.0, 100.0, 100.0, 5.0 )
		call StartSound(gg_snd_Ambience1)
		call PolledWait(1.25)
		loop
			exitwhen i>udg_Players
			if ConvertedPlayer(udg_Sorted[i])==GetLocalPlayer() then
				if udg_NightVision[udg_Sorted[i]]==false then
					call CinematicFilterGenericBJ( 0.0, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100.0, 100, 100.0, 5, 0, 0, 0, 100.0 )
					call CinematicFilterGenericBJ( 0.0, BLEND_MODE_BLEND, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 20.0, 20.0, 20.0, 0.0, 20.0, 20.0, 20.0, udg_Visibility )
				else
					call CinematicFilterGenericBJ( 5.0, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100.00, 100, 100.0, 100, 0, 80.0, 0, 25.0 )
				endif
			endif
			set i=i+1
		endloop
	endfunction

	function FogTransition takes real fog returns nothing
		local integer i = 1
		set udg_FogColor = fog
		if udg_Lighting then
			return
		endif
		loop
			exitwhen i>udg_InitialPlayers
			if ConvertedPlayer(udg_Sorted[i])==GetLocalPlayer() then
			   if udg_NightVision[udg_Sorted[i]]==false then
					call SetTerrainFogEx( 0, udg_ZStart, udg_ZEnd, 0.550, udg_FogColor, udg_FogColor, udg_FogColor )
				endif
			endif
			set i=i+1
		endloop
		call TriggerSleepAction(0.)
	endfunction

	function IntermissionRestore takes nothing returns nothing
		local integer i = 1
		if udg_Lighting==true then
			return
		endif
		loop
			exitwhen i>udg_InitialPlayers
			if ConvertedPlayer(udg_Sorted[i])==GetLocalPlayer() then
			   if udg_NightVision[udg_Sorted[i]]==false then
					call CinematicFilterGenericBJ( 0.0, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100.00, 100, 100.00, 5, 0, 0, 0, 100.00 )
					call CinematicFilterGenericBJ( 0.0, BLEND_MODE_BLEND, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 20.00, 20.00, 20.00, 0.00, 20.00, 20.00, 20.00, udg_Visibility )
				else
					call CinematicFilterGenericBJ( 0.0, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100.00, 100, 100.00, 100, 0, 80.00, 0, 25.00 )
				endif
			endif
			set i=i+1
		endloop
		call TriggerSleepAction(0.)
	endfunction



	private function CamFlash takes nothing returns nothing
		local integer i = 1
		set udg_Lighting = true
		call SetTerrainFogEx( 0, 2100.0, 4500.0, 0.250, 0.000, 0.000, 0.000 ) //0.25
		loop
			exitwhen i > udg_InitialPlayers
			if ConvertedPlayer(udg_Sorted[i])==GetLocalPlayer() then
				if udg_NightVision[udg_Sorted[i]]==false then
					call CinematicFilterGenericBJ( 0.1, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0.0, 25, 0.0, 100, 100.0, 100.00, 100.00, 5.00 )
				else
					call CinematicFilterGenericBJ( 0.1, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0.0, 100, 0.0, 100, 100.0, 100.00, 100.00, 5.00 )
				endif
			endif
			set i = i + 1
		endloop
		call PolledWait(0.1)
		set i = 1
		loop
			exitwhen i > udg_InitialPlayers
			if ConvertedPlayer(udg_Sorted[i])==GetLocalPlayer() then
				if udg_NightVision[udg_Sorted[i]]==false then
					call SetTerrainFogEx( 0, udg_ZStart, udg_ZEnd, 0.550, udg_FogColor, udg_FogColor, udg_FogColor )
					call CinematicFilterGenericBJ( 0.0, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100.00, 100, 100.00, 5, 0, 0, 0, 100.00 )
					call CinematicFilterGenericBJ( 0.0, BLEND_MODE_BLEND, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 20.00, 20.00, 20.00, 0.00, 20.00, 20.00, 20.00, udg_Visibility )
				else
					call CinematicFilterGenericBJ( 5.0, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100.00, 100, 100.00, 100, 0, 80.00, 0, 25.00 )
				endif
			endif
			set i = i + 1
		endloop
		set udg_Lighting = false
	endfunction

	function NightVision takes player whichPlayer, boolean b returns nothing
		if whichPlayer==GetLocalPlayer() then
			if (b) then
				if udg_progress=="day" then
					call CinematicFilterGenericBJ( 3.0, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0.0, 100.0, 0.0, 100.0, 0.0, 30.0, 0.0, 5.0 )
				else
					call SetTerrainFogEx(0,2300.0,4500.0,0.25,0.0,0.0,0.0) //0.25
					call CinematicFilterGenericBJ( 4.0, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 20.0, 25.0, 20.0, 75.0, 0.0, 80.0, 0.0, 25.0 )
				endif
			else
				call SetTerrainFogEx(0,udg_ZStart,udg_ZEnd,0.55,udg_FogColor,udg_FogColor,udg_FogColor)
				call CinematicFilterGenericBJ( 0.5, BLEND_MODE_BLEND, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 50.0, 100, 50.0, 0.0, 50.0, 100.0, 50.0, 100.0 )
				call CinematicFilterGenericBJ( 0.0, BLEND_MODE_BLEND, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 20.0, 20.0, 20.0, 0.0, 20.0, 20.0, 20.0, udg_Visibility )
			endif
		endif
	endfunction

	globals
		private boolean array CUSTOM_VIEW
		private integer array CUSTOM_Z_OFFSET
	endglobals
	
	function SetCustomAngle takes player p, integer i returns nothing
		local integer pid = GetPlayerId(p) + 1
		if i >= 300 and i <= 1000 then
			call SetCameraFieldForPlayer( p, CAMERA_FIELD_ANGLE_OF_ATTACK, 280.0, 1.0 )
			call SetCameraFieldForPlayer( p, CAMERA_FIELD_ZOFFSET, I2R(i), 0.8 )
			set CUSTOM_Z_OFFSET[pid] = i
			set CUSTOM_VIEW[pid] = true
		elseif i == -1 then
			call ResetToGameCameraForPlayer(p,1.0)
			set CUSTOM_Z_OFFSET[pid] = 0
			set CUSTOM_VIEW[pid] = false
		endif
	endfunction
	
	function SatelliteCamera takes nothing returns nothing
		local integer i = 1

		//call EnableTrigger(gg_trg_First_Person_Mode)
		call StartSound(gg_snd_SatCamZoom2)
		
		
		loop
			exitwhen i>udg_InitialPlayers
			if udg_FPSMode[udg_Sorted[i]]==false then
				call SetCameraFieldForPlayer( ConvertedPlayer(udg_Sorted[i]), CAMERA_FIELD_ANGLE_OF_ATTACK, 280.0, 1.0 )
				call SetCameraFieldForPlayer( ConvertedPlayer(udg_Sorted[i]), CAMERA_FIELD_ZOFFSET, 900.0, 0.8 )
			endif
			set i=i+1
		endloop
		
		call PolledWait(0.65)
		call DisplayTimedTextToPlayer( GetLocalPlayer(), 0.0, 0.0, 5.0, "Mission Time : " + udg_Clock[udg_Hour] + ":" + udg_Clock[udg_Minute] + ":" + udg_Clock[udg_Second] )
		call StartSound(gg_snd_SatCamShot)
		call CamFlash.execute()
		call PolledWait(0.4)
		if GetRandomInt(0,1)==1 then
			call StartSound(gg_snd_SatCamShot2)
			call CamFlash.execute()
		endif
		call TriggerSleepAction(0.)
		set i = 1
		loop
			exitwhen i>12
			
			if udg_FPSMode[i]==false then
				if CUSTOM_VIEW[i] then
					call SetCameraFieldForPlayer( ConvertedPlayer(i), CAMERA_FIELD_ANGLE_OF_ATTACK, 280.0, 1.0 )
					call SetCameraFieldForPlayer( ConvertedPlayer(i), CAMERA_FIELD_ZOFFSET, I2R(CUSTOM_Z_OFFSET[i]), 0.8 )
				else
					if GetPlayerSlotState(ConvertedPlayer(i)) != PLAYER_SLOT_STATE_EMPTY and GetPlayerController(ConvertedPlayer(i)) == MAP_CONTROL_USER then
						call ResetToGameCameraForPlayer(ConvertedPlayer(i),1.0)
					endif
				endif
			endif
			set i=i+1
		endloop
		call IntermissionRestore()
		if FPSCheck() then
			//call DisableTrigger(gg_trg_First_Person_Mode)
		endif
	endfunction

endlibrary